//package jl.security.core.controller;
//
//import com.google.code.kaptcha.Producer;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.imageio.ImageIO;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import java.awt.image.BufferedImage;
//import java.io.IOException;
//
///**
// * @author 江黎
// * @date 2022-02-08
// */
//@RestController
//public class CaptchaController {
//    /**
//     * 验证码 session key
//     */
//    public static final String SESSION_VERIFY_CODE = "captcha_codes:";
//
//    @Autowired
//    private Producer captchaProducer;
//
//    /**
//     * 生成验证码
//     */
//    @GetMapping("/captchaImage")
//    public void getCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
//        //1.获取验证码字符串
//        String code = captchaProducer.createText();
//        // 2. 字符串把它放到session中
//        HttpSession session = request.getSession();
//        session.setAttribute(SESSION_VERIFY_CODE, code);
//        // 3. 获取验证码图片
//        BufferedImage image = captchaProducer.createImage(code);
//        // 4. 将验证码图片把它写出去
//        // 禁止图片缓存
//        response.setHeader("Pragma", "no-cache");
//        response.setHeader("Cache-Control", "no-cache");
//        response.setDateHeader("Expires", 0);
//        ServletOutputStream out = response.getOutputStream();
//        ImageIO.write(image, "jpg", out);
//    }
//}
